package com.example.shopping_web_back.service;

import com.example.shopping_web_back.mapper.CustomerMapper;
import com.example.shopping_web_back.pojo.Customer;
import com.example.shopping_web_back.service.impl.CustomerServiceImpl;
import com.example.shopping_web_back.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

//主要用于定义顾客（用户）服务层函数的具体内容
@Service
public class CustomerService implements CustomerServiceImpl {

    @Autowired
    private CustomerMapper customerMapper;

    @Override
    public Customer findByCustomerName(String customer_name) {
        return customerMapper.findByCustomerName(customer_name);
    }

    @Override
    public void register(String customerName, String password) {
        customerMapper.add(customerName,password);
    }

    @Override
    public void update(Customer customer) {
        customerMapper.update(customer);
    }

    @Override
    public void updateImage(String imageUrl) {
        Map<String, Object> map = ThreadLocalUtil.get();
        Integer id = (Integer)map.get("id");
        customerMapper.updateImage(imageUrl, id);
    }

    @Override
    public void updatePassword(String newPwd) {
        Map<String, Object> map = ThreadLocalUtil.get();
        Integer id = (Integer)map.get("id");
        customerMapper.updatePassword(newPwd, id);
    }
}
